package com.yonyou.brigade.startup.controller;

import com.yonyou.brigade.basic_init.service.IDeveloperService;
import com.yonyou.brigade.basic_init.service.IUserCenterService;
import com.yonyou.brigade.util.mail.MailSenderUtil;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by Administrator on 2018/6/26.
 */
@Controller
public class HelloController {
    /**
     * 本地访问内容地址 ：http://localhost:8080/
     */
    @Autowired
    @Qualifier("userCenterServiceImpl")
    private IUserCenterService iUserCenterService;

    @Autowired
    @Qualifier("developerServiceImpl")
    private IDeveloperService developerService;

    @RequestMapping("/")
    public void helloHtml(HttpServletResponse response) throws IOException {
        PrintWriter writer = response.getWriter();

        writer.println("  ____    ____    ___    ____      _      ____    _____ ");
        writer.println(" | __ )  |  _ \\  |_ _|  / ___|    / \\    |  _ \\  | ____|");
        writer.println(" |  _ \\  | |_) |  | |  | |  _    / _ \\   | | | | |  _|  ");
        writer.println(" | |_) | |  _ <   | |  | |_| |  / ___ \\  | |_| | | |___ ");
        writer.println(" |____/  |_| \\_\\ |___|  \\____| /_/   \\_\\ |____/  |_____|");
    }

    @RequestMapping("/testconnect")
    public @ResponseBody
    Object testConnect(String phone, String tenant) {
        UcUserDto ucUserDto = iUserCenterService.getCompleteUcUserDtoByPhone(phone, tenant);
        return ucUserDto;
    }

    @RequestMapping("/test/test")
    public @ResponseBody Object testConnect() {
        return "检测成功";
    }

    @GetMapping("/test/mail/send")
    public void testMailSender() {
        List<String> mails = developerService.listEmailByType("KF");
        MailSenderUtil.sendCommonMail(mails, "你猜猜是啥", "因缺思厅");
    }
}
